<template>
  <div class="sms-news">
    <div class="title-box">
      <div class="title-name">消息通知</div>
      <moreDropdownMenu :routerConfig="routerListCofig"></moreDropdownMenu>
    </div>
    <div  v-if="smsList && smsList.length === 0" class="no-data">
      <img src="https://mt.heng-tai.com.cn/m-perfeval-pc/img/pc-other_zwsj_icon.4c654fe.png" alt="">
      <div>暂无数据</div>
    </div>
    <div v-if="smsList && smsList.length > 0" class="content" >
      <div :class="{readed: !!l.isRead}" v-for="l in smsList" class="content-item">
        <div class="news-name"  @click="lookDetail(l)">{{l.content}}</div>
        <span class="news-date">{{l.createdAt}}</span>
      </div>
    </div>
    <!-- 分页模块 -->
    <!-- <el-pagination
      small
      align="right"
      class="el-pagination-style"
      @size-change="sizeChange"
      @current-change="pageChange"
      :page-sizes="PAGE_NUMBER"
      :page-size="pageSize"
      :current-page="curPage"
      :layout="PAGINATION_LAYOUT"
      :total="totalElements"
      :pager-count="5"
      layout="total, prev, pager, next, jumper"
    /> -->
  </div>
</template>

<script>
import ellipsisForText from '@/moduleComponents/newWorkbench/ellipsisForText';
import moreDropdownMenu from '@/moduleComponents/newWorkbench/more-dropdown-menu';
import { PAGE_NUMBER, PAGINATION_LAYOUT } from '@const/common';
import {
  workbenchInformationNewNoticeList,
  workbenchInformationNoticepdateIsRead
} from '@const/mDataCenterApi.js';
export default {
  name: 'SmsNotice',
  components: {
    ellipsisForText,
    moreDropdownMenu
  },
  data() {
    return {
      smsList: [],
      routerListCofig: [
        {
          path: '/todoNoticeSet',
          label: '待办通知设置'
        }
      ],
      curPage: 1, // 当前页
      PAGE_NUMBER, // 页码数组
      PAGINATION_LAYOUT, // 页码功能布局
      pageSize: PAGE_NUMBER[0], // 一页的数量
      totalElements: 0 // 总共的条数
    };
  },
  created() {
    this.getSmsList();
  },
  methods: {
    // 获取消息通知列表
    getSmsList() {
      this.$axios({
        url: workbenchInformationNewNoticeList,
        method: 'post',
        data: {
          page: this.curPage,
          pageSize: this.pageSize,
          ignoreStatus: 0
        }
      })
        .then(res => {
          this.smsList = res.data.payload.content || [];
          this.totalElements = res.data.payload.totalElements;
        })
        .catch(err => {
          console.log(err);
        });
    },
    // 页码更改
    sizeChange(size) {
      this.pageSize = size;
      this.getSmsList();
    },
    // 切换不一样的页面,重置一切数据
    pageChange(curPage) {
      this.curPage = curPage;
      this.getSmsList();
    },
    // 设置为已读
    setRead(id, menuUrl) {
      this.$axios({
        url: workbenchInformationNoticepdateIsRead + `/${id}`,
        method: 'get'
      })
        .then(res => {
          if (res.data.code === '0') {
            this.getSmsList();
            if (menuUrl === 'null' || !menuUrl) {
              this.$message.warning('没有有效的跳转链接!');
              return;
            }
            window.open(menuUrl);
          }
        })
        .catch(err => {
          console.log(err);
        });
    },
    // 查看id
    lookDetail({ menuUrl, id, isRead }) {
      if (isRead) {
        if (menuUrl === 'null' || !menuUrl) {
          this.$message.warning('没有有效的跳转链接!');
          return;
        }
        window.open(menuUrl);
        return;
      }
      this.setRead(id, menuUrl);
    }
  }
};
</script>

<style scoped lang="less">
.sms-news {
  .content {
    padding-top: 10px;
    box-sizing: border-box;
    height: calc(100% - 20px);
    overflow: auto;
  }
  overflow: hidden;
  padding-bottom: 40px;
  box-sizing: border-box;
  .title-box {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    height: 48px;
    background-image: linear-gradient(to right, #e6edff, #fff);
    padding: 0 0 0 15px;
    box-sizing: border-box;
  }
  .title-name {
    font-size: 15px;
    color: #333333;
  }
  .news-name {
    width: 177px;
    height: 34px;
    font-size: 14px;
    color: #333;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: pointer;
  }
  .readed .news-name,
  .readed .title-name {
    color: #999;
  }
  .news-date {
    height: 34px;
    font-size: 14px;
    color: #999999;
  }
  .content-item {
    line-height: 34px;
    display: flex;
    justify-content: space-between;
    padding: 0 15px;
    box-sizing: border-box;
  }
  .no-data {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    height: 100%;
    font-size: 14px;
    color: #999999;
    margin-top: 5px;
    img {
      width: 172px;
      height: 100px;
      margin-bottom: 17px;
    }
  }
  /deep/ .el-pagination__jump {
    margin-left: 0;
  }
  /deep/ .el-pagination {
    padding: 5px 15px 0 0;
  }
  .readed {
    color: #ccc;
  }
}
</style>
